package com.fuli.app.filter;

import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authz.RolesAuthorizationFilter;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;

@Component
public class AnyRolesAuthorizationFilter extends RolesAuthorizationFilter {

    @Override
    public boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws IOException {
        Subject subject =this.getSubject(request,response);
        String [] rolesArray = (String[]) mappedValue;
        if(rolesArray==null||rolesArray.length==0)
            return true;
        for(int i = 0;i<rolesArray.length;i++){
            if(subject.hasRole(rolesArray[i]));
            return true;
        }
        return false;
    }
}
